package com.fanyouzhao.joker.send;

import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Map;

/**
 * author: fanyouzhao
 * date: 14:43 2021/9/16
 */
public class BarkSend {
    public static void send(Map<String, String> map){
        String key = "***";
        String title = map.get("title");
        String desp = map.get("desp");
        try {
            desp = URLEncoder.encode(desp, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        try {
            OkHttpClient client = new OkHttpClient();
            Request request = new Request.Builder()
                    .url("http://ip:port/"+key+"/"+title+"/"+desp)
                    .build();
            Response response = client.newCall(request).execute();
            // System.out.println(response);
            String responseData = null;
            if (response.body() != null) {
                responseData = response.body().string();
            }
            System.out.println("------------------------Bark推送响应------------------------\n"
                    + responseData);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
